/**
 * 计算两个时间差
 * @param time1Str
 * @param time2Str
*/
export const diffHours = (
    time1Str:string,
    time2Str:string
) => {  // 将字符串转换为Date对象
    const time1:any = new Date('2024-1-1 '+ time1Str);
    const time2:any = new Date('2024-1-1 '+ time2Str);
    // 确保两个时间都是有效的
    if (isNaN(time1.getTime()) || isNaN(time2.getTime())) {
        throw new Error('日期无效');
    }
    // 计算时间差（毫秒）
    const diffInMs = Math.abs(time2 - time1);
    // 将毫秒转换为小时
    const diffInHours = diffInMs / (1000 * 60 * 60)
    return +diffInHours.toFixed(2);
}
/**
 * 根据年获取月份一共几天
 * @param year
 * @param month
*/
export const getDaysInMonth = (
    year:string | number,
    month:string | number
) => {
    const date = new Date(+year, +month - 1, 1);
    date.setMonth(+month);
    const lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
    return lastDay;
}
/**
 * 查找符合条件的个数
 * @param arr Array
 * @param fn Function
*/
export const getEligibleNum = (arr:Array<any>,fn:Function)=>{
    return arr.filter((...arg)=>fn(...arg)).length
}